package com.luoyuanxiangvip.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luoyuanxiangvip.common.annotation.Cache;
import com.luoyuanxiangvip.common.enums.TemplateKeyEnum;
import com.luoyuanxiangvip.core.entity.SysTemplate;
import com.luoyuanxiangvip.core.mapper.SysTemplateMapper;
import com.luoyuanxiangvip.core.service.ISysTemplateService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 *
 * </p>
 *
 * @author luoyuanxiang <p>luoyuanxiangvip.com</p>
 * @since 2019/6/15
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysTemplateServiceImpl extends ServiceImpl<SysTemplateMapper, SysTemplate> implements ISysTemplateService {
    /**
     * 根据模板获取
     *
     * @param tmNewComment key
     * @return SysTemplate
     */
    @Override
    @Cache(value = "【template】根据key查询返回对象",expire = 7, unit = TimeUnit.DAYS)
    public SysTemplate getTemplate(TemplateKeyEnum tmNewComment) {
        return this.baseMapper.selectOne(new QueryWrapper<SysTemplate>()
                .eq("ref_key", tmNewComment.toString()));
    }
}
